from tkinter import *
from tkinter.ttk import Combobox


"""
    下拉框单元测试
"""
def enter_handle():  # 单击事件
    pass
    print(combobox_var.get())  # 获取值

def combobox_selected(event):  # 下拉框选择时触发
    print(combobox_var.get())  # 获取值
    pass

if __name__ == '__main__':
    window = Tk()
    window.geometry('400x200')
    values = ["唱歌", "跳舞", "绘画", "编程"]
    combobox_var = StringVar()
    combobox = Combobox(window, values=values, width=10, textvariable=combobox_var)
    combobox_var.set(values[2])  # 设置值为第三个
    combobox.bind("<<ComboboxSelected>>", combobox_selected)  # 绑定下拉框选择事件
    combobox.pack()
    Button(window, text='确定', cursor="hand2", command=enter_handle).pack()
    window.mainloop()
